package net.expectx.gw.util;

import java.math.BigDecimal;
import java.util.Random;

public class AdminUtil {
    /**
     * 生成 num位的随机数
     * @param num
     * @return
     */
    public static int randomSmsCode(final int num) {
        Random rand = new Random();
        int first = rand.nextInt(10);
        if(first == 0) {
            first = 6;
        }
        String code = String.valueOf(first);
        for(int i = 1; i < num; i++) {
            code += rand.nextInt(10);
        }
        return Integer.parseInt(code);
    }
    public static Double calcBodyMassIndex(Double weight,Double height){
        Double result=0D;
        result=(weight/(height*height))*10000;
        BigDecimal b = new BigDecimal(result);
        result = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return  result;
    }

    /**
     * 标准体重=自身身高-105
     * 体重指数=体重/身高的平方
     * 标准体重正负10%为正常体重
     * 标准体重正负10%-20%为体重过重或过轻
     * 标准体重正负20%以上为肥胖或体重不足
     * 体重偏低
     */
    public static String calcObesity(Double bodyMassIndex){
        String result="";
        if (bodyMassIndex<18.5){
            result="体重过低";
        }else if(bodyMassIndex>=18.5 && bodyMassIndex<=24.9){
            result="体重正常";
        }else if(bodyMassIndex>=25 && bodyMassIndex<=29.9){
            result="体重超重";
        }else{
            result="体重肥胖";
        }
        return  result;
    }
    public static void main(String [] args){
        System.out.println(calcObesity(calcBodyMassIndex(90d,180d)));
    }
}
